<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of character
 * 
 * @author trambauern
 */
class character {
    /**
	 * @param int $status 
	 * @return Number of Characters Online / Offline
     */

    public function getChars($status = "") {
        global $connection;
        if (!is_numeric($status)) {
            $sql = 'SELECT id, online FROM ' . DB_GAME . '.players';
            $dbh = $connection->prepare($sql);
            $dbh->execute();
        } elseif ($status == 1 || $status == 2) {
            if ($status == 2) {
                $status = 0;
            }
            $sql = 'SELECT id, online FROM ' . DB_GAME . '.players WHERE online = :online';
            $dbh = $connection->prepare($sql);
            $dbh->bindValue(':online', $status);
            $dbh->execute();
        }
        $num = $dbh->rowCount();


        return $num;
    }

    /* Get Character Level */

    public function getLevel($char_exp , $data = '') {
		if(!empty($data)) {
			global $connection;
			$sql = 'SELECT * FROM '.DB_GAME.'.players WHERE id = :id';
			$dbh = $connection->prepare($sql);
			$dbh->bindValue(':id', $data);
			$dbh->execute();
			$row = $dbh->fetch(PDO::FETCH_ASSOC);
			$char_exp = $row['exp'];
		}
		
		if ($char_exp <= 0) {
            $exp = 1;
        } elseif ($char_exp <= 650) {
            $exp = 1;
        } elseif ($char_exp <= 2567) {
            $exp = 2;
        } elseif ($char_exp <= 6797) {
            $exp = 3;
        } elseif ($char_exp <= 15490) {
            $exp = 4;
        } elseif ($char_exp <= 30073) {
            $exp = 5;
        } elseif ($char_exp <= 52958) {
            $exp = 6;
        } elseif ($char_exp <= 87894) {
            $exp = 7;
        } elseif ($char_exp <= 140329) {
            $exp = 8;
        } elseif ($char_exp <= 213454) {
            $exp = 9;
        } elseif ($char_exp <= 307558) {
            $exp = 10;
        } elseif ($char_exp <= 483553) {
            $exp = 11;
        } elseif ($char_exp <= 608161) {
            $exp = 12;
        } elseif ($char_exp <= 825336) {
            $exp = 13;
        } elseif ($char_exp <= 1091985) {
            $exp = 14;
        } elseif ($char_exp <= 1418170) {
            $exp = 15;
        } elseif ($char_exp <= 1810467) {
            $exp = 16;
        } elseif ($char_exp <= 2332547) {
            $exp = 17;
        } elseif ($char_exp <= 3002259) {
            $exp = 18;
        } elseif ($char_exp <= 3820081) {
            $exp = 19;
        } elseif ($char_exp <= 4820228) {
            $exp = 20;
        } elseif ($char_exp <= 6115322) {
            $exp = 21;
        } elseif ($char_exp <= 7725199) {
            $exp = 22;
        } elseif ($char_exp <= 9727123) {
            $exp = 23;
        } elseif ($char_exp <= 12075781) {
            $exp = 24;
        } elseif ($char_exp <= 14762522) {
            $exp = 25;
        } elseif ($char_exp <= 17879938) {
            $exp = 26;
        } elseif ($char_exp <= 21482201) {
            $exp = 27;
        } elseif ($char_exp <= 25494737) {
            $exp = 28;
        } elseif ($char_exp <= 30171209) {
            $exp = 29;
        } elseif ($char_exp <= 35999532) {
            $exp = 30;
        } elseif ($char_exp <= 42807774) {
            $exp = 31;
        } elseif ($char_exp <= 50898898) {
            $exp = 32;
        } elseif ($char_exp <= 60588305) {
            $exp = 33;
        } elseif ($char_exp <= 73257434) {
            $exp = 34;
        } elseif ($char_exp <= 89381899) {
            $exp = 35;
        } elseif ($char_exp <= 109123921) {
            $exp = 36;
        } elseif ($char_exp <= 135145762) {
            $exp = 37;
        } elseif ($char_exp <= 165021833) {
            $exp = 38;
        } elseif ($char_exp <= 201169803) {
            $exp = 39;
        } elseif ($char_exp <= 243343723) {
            $exp = 40;
        } elseif ($char_exp <= 292699203) {
            $exp = 41;
        } elseif ($char_exp <= 350659083) {
            $exp = 42;
        } elseif ($char_exp <= 415031452) {
            $exp = 43;
        } elseif ($char_exp <= 485413854) {
            $exp = 44;
        } elseif ($char_exp <= 559280864) {
            $exp = 45;
        } elseif ($char_exp <= 643809037) {
            $exp = 46;
        } elseif ($char_exp <= 741317548) {
            $exp = 47;
        } elseif ($char_exp <= 853743989) {
            $exp = 48;
        } elseif ($char_exp <= 982653882) {
            $exp = 49;
        } elseif ($char_exp <= 1128723910) {
            $exp = 50;
        } elseif ($char_exp <= 1306188688) {
            $exp = 51;
        } elseif ($char_exp <= 1510443689) {
            $exp = 52;
        } elseif ($char_exp <= 1746929453) {
            $exp = 53;
        } elseif ($char_exp <= 2018321807) {
            $exp = 54;
        } elseif ($char_exp <= 2320050276) {
            $exp = 55;
        } elseif ($char_exp <= 2666120304) {
			$exp = 56;
		} elseif ($char_exp <= 3052865037) {
			$exp = 57;
		} elseif ($char_exp <= 3476726163) {
			$exp = 58;
		} elseif ($char_exp <= 3945498124) {
			$exp = 59;
		} elseif ($char_exp <= 4448612196) {
			$exp = 60;
		}
        return $exp;
    }

    function getClass($class, $sub = '') {
        global $lang;
		if(empty($sub)) {
			$language = parse_ini_file('../'.$lang . '/character.function.php', true);
		} elseif($sub === 1) {
			$language = parse_ini_file($lang . '/character.function.php', true);
		}
        $player_class = "";
        if ($class == 'WARRIOR') {
            $player_class = $language['warrior'];
        } elseif ($class == 'GLADIATOR') {
            $player_class = $language['gladiator'];
        } elseif ($class == 'TEMPLAR') {
            $player_class = $language['templar'];
        } elseif ($class == 'SCOUT') {
            $player_class = $language['scout'];
        } elseif ($class == 'ASSASSIN') {
            $player_class = $language['assassine'];
        } elseif ($class == 'RANGER') {
            $player_class = $language['ranger'];
        } elseif ($class == 'MAGE') {
            $player_class = $language['mage'];
        } elseif ($class == 'SORCERER') {
            $player_class = $language['sorcerer'];
        } elseif ($class == 'SPIRIT_MASTER') {
            $player_class = $language['spirit_master'];
        } elseif ($class == 'PRIEST') {
            $player_class = $language['priest'];
        } elseif ($class == 'CLERIC') {
            $player_class = $language['cleric'];
        } elseif ($class == 'CHANTER') {
            $player_class = $language['chanter'];
        }

        return $player_class;
    }

    function getRace($race, $flags = 3, $sub = '') {
        global $lang;
		if(empty($sub)) {
			$language = parse_ini_file('../'.$lang . '/character.function.php', true);
		} elseif($sub === 1) {
			$language = parse_ini_file($lang . '/character.function.php', true);
		}
        $flagIcon = 1;
        $flagTitle = 2;

        $return = "";

        if ($race == 'ELYOS') {
            if ($flags & $flagIcon)
                $return .= "<span style='display:none;'>1</span><img title='Elyos' class='ui-li-icon ui-li-thumb' align='absmiddle' height='15' width='15' src='_images/icons/elyos.gif' /> ";
            if ($flags & $flagTitle)
                $return .= $language['elyos'];
        }
        elseif ($race == 'ASMODIANS') {
            if ($flags & $flagIcon)
                $return .= "<span style='display:none;'>2</span><img title='Asmodier' class='ui-li-icon ui-li-thumb' align='absmiddle' height='15' width='15'  src='_images/icons/asmodian.gif' /> ";
            if ($flags & $flagTitle)
                $return .= $language['asmodians'];
        }
        return $return;
    }
	function getAccountID($data) {
		global $connection;
		$sql = 'SELECT id, name, account_id FROM '.DB_GAME.'.players WHERE name = :data OR id = :data';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':data', $data);
		$dbh->execute();
		$row = $dbh->fetch(PDO::FETCH_ASSOC);
		return $row['account_id'];
	}
	function getCharName($data) {
		global $connection;
		$sql = 'SELECT id, name FROM '.DB_GAME.'.players WHERE id = :data';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':data', $data);
		$dbh->execute();
		$row = $dbh->fetch(PDO::FETCH_ASSOC);
		return $row['name'];
	}
	function getCharId($data) {
		global $connection;
		$sql = 'SELECT id, name FROM '.DB_GAME.'.players WHERE name = :data';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':data', $data);
		$dbh->execute();
		$row = $dbh->fetch(PDO::FETCH_ASSOC);
		return $row['id'];
	}
	function showStatus($data) {
		global $connection;
		global $lang;
        $language = parse_ini_file($lang . "/main.layout.php", true);
		
		$sql = 'SELECT * FROM '.DB_GAME.'.players WHERE id = :data';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':data', $data);
		$dbh->execute();
		$row = $dbh->fetch(PDO::FETCH_ASSOC);
		if($row['online'] === 1) {
			$status = $language['online']; 
		} else {
			$status = $language['offline'];
		}
		return $status;
	}
	function legionName ($data) {
		global $connection;
		$sql = 'SELECT * FROM '.DB_GAME.'.legion_members WHERE player_id = :data';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':data', $data);
		$dbh->execute();
		$row = $dbh->fetch(PDO::FETCH_ASSOC);
		
		$sql = 'SELECT * FROM '.DB_GAME.'.legions WHERE id = :legion_id';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':legion_id', $row['legion_id']);
		$dbh->execute();
		$row_legion = $dbh->fetch(PDO::FETCH_ASSOC);

		return $row_legion['name'];
		
	}
	function getAbyssKills($data) {
		global $connection;
		$sql = 'SELECT * FROM '.DB_GAME.'.abyss_rank WHERE player_id = :data';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':data', $data);
		$dbh->execute();
		$row = $dbh->fetch(PDO::FETCH_ASSOC);
		return $row['all_kill'];
	}
	function getAbyssPoints($data) {
		global $connection;
		$sql = 'SELECT * FROM '.DB_GAME.'.abyss_rank WHERE player_id = :data';
		$dbh = $connection->prepare($sql);
		$dbh->bindValue(':data', $data);
		$dbh->execute();
		$row = $dbh->fetch(PDO::FETCH_ASSOC);
		return $row['ap'];
	}
}

?>
